from docutils.nodes import table


class HouseItem:
    def __init__(self,name,area):
        self.name = name
        self.area = area

    def __str__(self):
        return f'{self.name} 占地{self.area}'


class House:
    def __init__(self,house_type,area):
        self.house_type = house_type
        self.area = area
        self.free_area = area
        self.item_list = []

    def __str__(self):
        return (f'户型： {self.house_type}\n'
                f'总面积：{self.area}'
                f'剩余：{self.free_area}\n'
                f'家具:{self.item_list}')
    #注解方便联想
    def add_item(self,item:HouseItem):
        #判断神域面积还够不
        if self.free_area >=0:
            self.item_list.append(item.name)
            self.free_area -= item.area #剩余面积减少
            print(f'剩余面积{self.free_area}')

        else:
            print('空间不够')

bed = HouseItem('席梦思',4)
chest = HouseItem('衣柜',2)
table1 = HouseItem('餐桌',1.5)

print(bed)
print(chest)
print(table1)
print('-'*50)
house = House('二室一厅',5)

house.add_item(bed)
house.add_item(chest)
house.add_item(table1)
print(house)



